home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / history.test < prev    next >
Text File  |  1993-02-06  |  13KB  |  401 lines

  1. # Commands covered:  history
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/history.test,v 1.8 93/02/06 15:53:54 ouster Exp $ (Berkeley)
  28.   
  29. if {[info commands history] == ""} {
  30.     puts stdout "This version of Tcl was built without the history command;\n"
  31.     puts stdout "history tests will be skipped.\n"
  32.     return
  33. }
  34.  
  35. if {[string compare test [info procs test]] == 1} then {source defs}
  36.  
  37. set num [history nextid]
  38. history keep 3
  39. history add {set a 12345}
  40. history add {set b [format {A test %s} string]}
  41. history add {Another test}
  42.  
  43. # "history event"
  44.  
  45. test history-1.1 {event option} {history event -1} \
  46.     {set b [format {A test %s} string]}
  47. test history-1.2 {event option} {history event $num} \
  48.     {set a 12345}
  49. test history-1.3 {event option} {history event [expr $num+2]} \
  50.     {Another test}
  51. test history-1.4 {event option} {history event set} \
  52.     {set b [format {A test %s} string]}
  53. test history-1.5 {event option} {history e "* a*"} \
  54.     {set a 12345}
  55. test history-1.6 {event option} {catch {history event *gorp} msg} 1
  56. test history-1.7 {event option} {
  57.     catch {history event *gorp} msg
  58.     set msg
  59. } {no event matches "*gorp"}
  60. test history-1.8 {event option} {history event} \
  61.     {set b [format {A test %s} string]}
  62. test history-1.9 {event option} {catch {history event 123 456} msg} 1
  63. test history-1.10 {event option} {
  64.     catch {history event 123 456} msg
  65.     set msg
  66. } {wrong # args: should be "history event ?event?"}
  67.  
  68. # "history redo"
  69.  
  70. set a 0
  71. history redo -2
  72. test history-2.1 {redo option} {set a} 12345
  73. set b 0
  74. history redo
  75. test history-2.2 {redo option} {set b} {A test string}
  76. test history-2.3 {redo option} {catch {history redo -3 -4}} 1
  77. test history-2.4 {redo option} {
  78.     catch {history redo -3 -4} msg
  79.     set msg
  80. } {wrong # args: should be "history redo ?event?"}
  81.  
  82. # "history add"
  83.  
  84. history add "set a 444" exec
  85. test history-3.1 {add option} {set a} 444
  86. test history-3.2 {add option} {catch {history add "set a 444" execGorp}} 1
  87. test history-3.3 {add option} {
  88.     catch {history add "set a 444" execGorp} msg
  89.     set msg
  90. } {bad argument "execGorp": should be "exec"}
  91. test history-3.4 {add option} {catch {history add "set a 444" a} msg} 1
  92. test history-3.5 {add option} {
  93.     catch {history add "set a 444" a} msg
  94.     set msg
  95. } {bad argument "a": should be "exec"}
  96. history add "set a 555" e
  97. test history-3.6 {add option} {set a} 555
  98. history add "set a 666"
  99. test history-3.7 {add option} {set a} 555
  100. test history-3.8 {add option} {catch {history add "set a 666" e f} msg} 1
  101. test history-3.9 {add option} {
  102.     catch {history add "set a 666" e f} msg
  103.     set msg
  104. } {wrong # args: should be "history add event ?exec?"}
  105.  
  106. # "history change"
  107.  
  108. history change "A test value"
  109. test history-4.1 {change option} {history event [expr {[history n]-1}]} \
  110.     "A test value"
  111. history c "Another test" -1
  112. test history-4.2 {change option} {history e} "Another test"
  113. test history-4.3 {change option} {history event [expr {[history n]-1}]} \
  114.     "A test value"
  115. test history-4.4 {change option} {catch {history change Foo 4 10}} 1
  116. test history-4.5 {change option} {
  117.     catch {history change Foo 4 10} msg
  118.     set msg
  119. } {wrong # args: should be "history change newValue ?event?"}
  120. test history-4.6 {change option} {
  121.     catch {history change Foo [expr {[history n]-4}]}
  122. } 1
  123. test history-4.7 {change option} {
  124.     catch {history change Foo [expr {[history n]-4}]}
  125.     set msg
  126. } {wrong # args: should be "history change newValue ?event?"}
  127.  
  128. # "history info"
  129.  
  130. set num [history n]
  131. history add set\ a\ {b\nc\ d\ e}
  132. history add {set b 1234}
  133. history add set\ c\ {a\nb\nc}
  134. test history-5.1 {info option} {history info} [format {%6d  set a {b
  135.     c d e}
  136. %6d  set b 1234
  137. %6d  set c {a
  138.     b
  139.     c}} $num [expr $num+1] [expr $num+2]]
  140. test history-5.2 {info option} {history i 2} [format {%6d  set b 1234
  141. %6d  set c {a
  142.     b
  143.     c}} [expr $num+1] [expr $num+2]]
  144. test history-5.3 {info option} {catch {history i 2 3}} 1
  145. test history-5.4 {info option} {
  146.     catch {history i 2 3} msg
  147.     set msg
  148. } {wrong # args: should be "history info ?count?"}
  149. test history-5.5 {info option} {history} [format {%6d  set a {b
  150.     c d e}
  151. %6d  set b 1234
  152. %6d  set c {a
  153.     b
  154.     c}} $num [expr $num+1] [expr $num+2]]
  155.  
  156. # "history keep"
  157.  
  158. history add "foo1"
  159. history add "foo2"
  160. history add "foo3"
  161. history keep 2
  162. test history-6.1 {keep option} {history event [expr [history n]-1]} foo3
  163. test history-6.2 {keep option} {history event -1} foo2
  164. test history-6.3 {keep option} {catch {history event -3}} 1
  165. test history-6.4 {keep option} {
  166.     catch {history event -3} msg
  167.     set msg
  168. } {event "-3" is too far in the past}
  169. history k 5
  170. test history-6.5 {keep option} {history event -1} foo2
  171. test history-6.6 {keep option} {history event -2} {}
  172. test history-6.7 {keep option} {history event -3} {}
  173. test history-6.8 {keep option} {history event -4} {}
  174. test history-6.9 {keep option} {catch {history event -5}} 1
  175. test history-6.10 {keep option} {catch {history keep 4 6}} 1
  176. test history-6.11 {keep option} {
  177.     catch {history keep 4 6} msg
  178.     set msg
  179. } {wrong # args: should be "history keep number"}
  180. test history-6.12 {keep option} {catch {history keep}} 1
  181. test history-6.13 {keep option} {
  182.     catch {history keep} msg
  183.     set msg
  184. } {wrong # args: should be "history keep number"}
  185. test history-6.14 {keep option} {catch {history keep -3}} 1
  186. test history-6.15 {keep option} {
  187.     catch {history keep -3} msg
  188.     set msg
  189. } {illegal keep count "-3"}
  190.  
  191. # "history nextid"
  192.  
  193. set num [history n]
  194. history add "Testing"
  195. history add "Testing2"
  196. test history-7.1 {nextid option} {history event} "Testing"
  197. test history-7.2 {nextid option} {history next} [expr $num+2]
  198. test history-7.3 {nextid option} {catch {history nextid garbage}} 1
  199. test history-7.4 {nextid option} {
  200.     catch {history nextid garbage} msg
  201.     set msg
  202. } {wrong # args: should be "history nextid"}
  203.  
  204. # "history substitute"
  205.  
  206. test history-8.1 {substitute option} {
  207.     history add "set a {test foo test b c test}"
  208.     history add "Test command 2"
  209.     set a 0
  210.     history substitute foo bar -1
  211.     set a
  212. } {test bar test b c test}
  213. test history-8.2 {substitute option} {
  214.     history add "set a {test foo test b c test}"
  215.     history add "Test command 2"
  216.     set a 0
  217.     history substitute test gorp
  218.     set a
  219. } {gorp foo gorp b c gorp}
  220. test history-8.3 {substitute option} {
  221.     history add "set a {test foo test b c test}"
  222.     history add "Test command 2"
  223.     set a 0
  224.     history sub " te" to
  225.     set a
  226. } {test footost b ctost}
  227. test history-8.4 {substitute option} {catch {history sub xxx yyy}} 1
  228. test history-8.5 {substitute option} {
  229.     catch {history sub xxx yyy} msg
  230.     set msg
  231. } {"xxx" doesn't appear in event}
  232. test history-8.6 {substitute option} {catch {history s a b -10}} 1
  233. test history-8.7 {substitute option} {
  234.     catch {history s a b -10} msg
  235.     set msg
  236. } {event "-10" is too far in the past}
  237. test history-8.8 {substitute option} {catch {history s a b -1 20}} 1
  238. test history-8.9 {substitute option} {
  239.     catch {history s a b -1 20} msg
  240.     set msg
  241. } {wrong # args: should be "history substitute old new ?event?"}
  242.  
  243. # "history words"
  244.  
  245. test history-9.1 {words option} {
  246.     history add {word0 word1 word2 a b c word6}
  247.     history add foo
  248.     history words 0-$
  249. } {word0 word1 word2 a b c word6}
  250. test history-9.2 {words option} {
  251.     history add {word0 word1 word2 a b c word6}
  252.     history add foo
  253.     history w 2 -1
  254. } word2
  255. test history-9.3 {words option} {
  256.     history add {word0 word1 word2 a b c word6}
  257.     history add foo
  258.     history wo $
  259. } word6
  260. test history-9.4 {words option} {catch {history w 1--1} msg} 1
  261. test history-9.5 {words option} {
  262.     catch {history w 1--1} msg
  263.     set msg
  264. } {bad word selector "1--1":  should be num-num or pattern}
  265. test history-9.6 {words option} {
  266.     history add {word0 word1 word2 a b c word6}
  267.     history add foo
  268.     history w w
  269. } {}
  270. test history-9.7 {words option} {
  271.     history add {word0 word1 word2 a b c word6}
  272.     history add foo
  273.     history w *2
  274. } word2
  275. test history-9.8 {words option} {
  276.     history add {word0 word1 word2 a b c word6}
  277.     history add foo
  278.     history w *or*
  279. } {word0 word1 word2 word6}
  280. test history-9.9 {words option} {catch {history words 10}} 1
  281. test history-9.10 {words option} {
  282.     catch {history words 10} msg
  283.     set msg
  284. } {word selector "10" specified non-existent words}
  285. test history-9.11 {words option} {catch {history words 1 -1 20}} 1
  286. test history-9.12 {words option} {
  287.     catch {history words 1 -1 20} msg
  288.     set msg
  289. } {wrong # args: should be "history words num-num/pat ?event?"}
  290.  
  291. # history revision
  292.  
  293. test history-10.1 {history revision} {
  294.     set a 0
  295.     history a {set a 12345}
  296.     history a {set a [history e]} exec
  297.     set a
  298. } {set a 12345}
  299. test history-10.2 {history revision} {
  300.     set a 0
  301.     history a {set a 12345}
  302.     history a {set a [history e]} exec
  303.     history a foo
  304.     history ev -1
  305. } {set a {set a 12345}}
  306. test history-10.3 {history revision} {
  307.     set a 0
  308.     history a {set a 12345}
  309.     history a {set a [history e]} exec
  310.     history a foo
  311.     history a {history r -2} exec
  312.     history a {set a 12345}
  313.     history ev -1
  314. } {set a {set a 12345}}
  315. test history-10.4 {history revision} {
  316.     history a {set a 12345}
  317.     history a {history s 123 999} exec
  318.     history a foo
  319.     history ev -1
  320. } {set a 99945}
  321. test history-10.5 {history revision} {
  322.     history add {word0 word1 word2 a b c word6}
  323.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  324.     set a
  325. } {word0 {a b}}
  326. test history-10.6 {history revision} {
  327.     history add {word0 word1 word2 a b c word6}
  328.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  329.     history add foo
  330.     history ev
  331. } {set a [list word0 {a b}]}
  332. test history-10.7 {history revision} {
  333.     history add {word0 word1 word2 a b c word6}
  334.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  335.     history add {format b}
  336.     history add {word0 word1 word2 a b c word6}
  337.     set a 0
  338.     history add {set [history subs b a -2] [list abc [history r -2] [history w 1-3]]} exec
  339.     history add foo
  340.     history ev
  341. } {set [format a] [list abc [format b] {word1 word2 a}]}
  342. test history-10.8 {history revision} {
  343.     history add {set a 12345}
  344.     concat a b c
  345.     history add {history redo; set b 44} exec
  346.     history add foo
  347.     history ev
  348. } {set a 12345; set b 44}
  349. test history-10.9 {history revision} {
  350.     history add {set a 12345}
  351.     history add {history redo; history change "A simple test"; history subs 45 xx} exec
  352.     set a
  353. } 123xx
  354. test history-10.10 {history revision} {
  355.     history add {set a 12345}
  356.     history add {history redo; history change "A simple test"; history subs 45 xx} exec
  357.     history add foo
  358.     history e
  359. } {A simple test}
  360. test history-10.11 {history revision} {
  361.     history add {word0 word1 $ a b c word6}
  362.     history add {set a [history w 4-[history word 2]]} exec
  363.     set a
  364. } {b c word6}
  365. test history-10.12 {history revision} {
  366.     history add {word0 word1 $ a b c word6}
  367.     history add {set a [history w 4-[history word 2]]} exec
  368.     history add foo
  369.     history e
  370. } {set a {b c word6}}
  371. test history-10.13 {history revision} {
  372.     history add {history word 0} exec
  373.     history add foo
  374.     history e
  375. } {history word 0}
  376. test history-10.14 {history revision} {
  377.     history add {set a [history word 0; format c]} exec
  378.     history add foo
  379.     history e
  380. } {set a [history word 0; format c]}
  381. test history-10.15 {history revision even when nested} {
  382.     proc x {a b} {history word $a $b}
  383.     history add {word1 word2 word3 word4}
  384.     history add {set a [x 1-3 -1]} exec
  385.     history add foo
  386.     history e
  387. } {set a {word2 word3 word4}}
  388. test history-10.16 {disable history revision in nested history evals} {
  389.     history add {word1 word2 word3 word4}
  390.     history add {set a [history words 0]; history add foo; set a [history words 0]} exec
  391.     history e
  392. } {set a word1; history add foo; set a [history words 0]}
  393.  
  394. # miscellaneous
  395.  
  396. test history-11.1 {miscellaneous} {catch {history gorp} msg} 1
  397. test history-11.2 {miscellaneous} {
  398.     catch {history gorp} msg
  399.     set msg
  400. } {bad option "gorp": must be add, change, event, info, keep, nextid, redo, substitute, or words}
  401.